翻訳と辞書
Words near each other
・ "O" Is for Outlaw
・ "O"-Jung.Ban.Hap.
・ "Ode-to-Napoleon" hexachord
・ "Oh Yeah!" Live
・ "Our Contemporary" regional art exhibition (Leningrad, 1975)
・ "P" Is for Peril
・ "Pimpernel" Smith
・ "Polish death camp" controversy
・ "Pro knigi" ("About books")
・ "Prosopa" Greek Television Awards
・ "Pussy Cats" Starring the Walkmen
・ "Q" Is for Quarry
・ "R" Is for Ricochet
・ "R" The King (2016 film)
・ "Rags" Ragland
・ ! (album)
・ ! (disambiguation)
・ !!
・ !!!
・ !!! (album)
・ !!Destroy-Oh-Boy!!
・ !Action Pact!
・ !Arriba! La Pachanga
・ !Hero
・ !Hero (album)
・ !Kung language
・ !Oka Tokat
・ !PAUS3
・ !T.O.O.H.!
・ !Women Art Revolution


Dictionary Lists
翻訳と辞書 辞書検索 [ 開発暫定版 ]
スポンサード リンク

command substitution : ウィキペディア英語版
command substitution
In computing, command substitution is a facility that allows a command to be run and its output to be pasted back on the command line as arguments to another command. Command substitution first appeared in the Bourne shell,〔Dahdah, Howard. (''The A-Z of Programming Languages: Bourne shell, or sh, An in-depth interview with Steve Bourne, creator of the Bourne shell, or sh ), Computerworld, March 5, 2009.〕 introduced with Unix 7th Edition in 1979, and has remained a characteristic of all later Unix shells. The feature has since been adopted in other programming languages as well, including Perl, PHP, Ruby and Microsoft's Powershell under Windows. It also appears in Microsoft's CMD.EXE in the FOR command and the ( ) command.
==Syntax and semantics==

Shells typically implement command substitution by creating a child process to run the first command with its standard output piped back to the shell, which reads that output, parsing it into words separated by whitespace. Because the shell can't know it has all the output from the child until the pipe closes or the child dies, it waits until then before it starts another child process to run the second command.
This C shell example shows how one might search for all the C files containing the string malloc using fgrep and then edit any that are found using the vi editor. The syntactical notation shown here, ` ... `, using backquotes as delimiters, is the original style and is supported by all the common Unix shells.

#!/bin/csh
vi `fgrep -l malloc
*.c`

Objections have been raised to both the syntax, how it's typed, and the semantics, how it works.
The syntax has been criticized as easy to type, an important factor for an interactive command processor, but awkward to nest, putting one command substitution inside another, because both the left and the right delimiters are the same.〔(Unix Power Tools: 45.31 Nested Command Substitution. )〕 Bash 2.0〔(Bash Prompt HOWTO: 3.3. Command Substitution. )〕 and the Korn shell (ksh)〔
〕 solved this with an alternative notation, $( ... ), borrowing from the notational style used for variable substitution. Microsoft's PowerShell also uses this notation, with the same semantics.

#!/bin/bash
vi $(fgrep -l malloc
*.c)

The semantics, breaking the output into words at whitespace, has also been criticized. It worked well on early Unix systems where filenames never contained spaces but it doesn't work at all well on modern Windows and Linux systems where filenames certainly can contain spaces.〔
〕 In either of these previous examples, if any of the filenames matched by the
*.c
wildcard contains a space, that filename will be broken into two separate arguments to vi, clearly not what was intended. Hamilton C shell solved this with a double backquote notation, `` ... ``, that parses into words only at line breaks.〔

This is an example of command substitution
using the () operator in PowerShell:

$MyVariable = (ls)
echo $MyVariable


抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)
ウィキペディアで「command substitution」の詳細全文を読む



スポンサード リンク
翻訳と辞書 : 翻訳のためのインターネットリソース

Copyright(C) kotoba.ne.jp 1997-2016. All Rights Reserved.